import { IData } from './drawLine_one'

export type IBody = IData['body']

export const getBodySize = (body: IBody): [number, number] => {
    const ul = document.createElement('ul')
    ul.style.width = '200px'
    ul.style.height = 'auto'
    ul.style.listStyle = 'none'
    ul.style.visibility = 'hidden'

    body.forEach((cont) => {
        const li = document.createElement('li')
        li.style.width = '100%'
        li.style.height = 'auto'
        li.style.marginBottom = '20px'

        const p1 = document.createElement('p')
        p1.innerText = cont.text

        const p2 = document.createElement('p')
        const lb1 = document.createElement('label')
        lb1.innerText = '人员'
        const em1 = document.createElement('em')
        em1.innerText = cont.peo.toString()

        const p3 = document.createElement('p')
        const lb2 = document.createElement('label')
        lb2.innerText = '组织'
        const em2 = document.createElement('em')
        em2.innerText = cont.org.toString()

        for (let p of [p1, p2, p3]) {
            p.style.wordBreak = 'break-all'
            p.style.textAlign = 'justify'
            p.style.fontSize = '13px'
        }

        ul.append(li)
        li.append(p1)
        
        li.append(p2)
        p2.append(lb1)
        p2.append(em1)

        li.append(p3)
        p3.append(lb2)
        p3.append(em2)
    })
    document.body.append(ul)
    const { width, height } = ul.getBoundingClientRect()
    document.body.removeChild(ul)
    return [width, height]
}